package com.atguigu.flink.chapter10.sql;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2023/6/27 14:20
 */
public class SQLDemo2 {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
//        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        tEnv.executeSql("create table sensor(" +
                            " id string, " +
                            " ts bigint, " +
                            " vc int " +
                            ")with(" +
                            "  'connector' = 'kafka', " +
                            "  'topic' = 's1', " +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
                            "  'properties.group.id' = 'atguigu', " +
                            "  'scan.startup.mode' = 'earliest-offset', " +
                            "  'format' = 'csv' " +
                            ")");
        
        
        /*tEnv.executeSql("create table s_copy " +
                            "like sensor");*/
        
        tEnv.executeSql("create table s_copy " +
                            "with(" +
                            "  'connector' = 'kafka', " +
                            "  'topic' = 's10', " +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
                            "  'properties.group.id' = 'atguigu', " +
                            "  'scan.startup.mode' = 'latest-offset', " +
                            "  'format' = 'csv' " +
                            ")" +
                            " as select id, vc, ts from sensor ");
        
        Table sensor = tEnv.from("sensor");
        Table s_copy = tEnv.from("s_copy");
        
        sensor.printSchema();
        s_copy.printSchema();
        
        s_copy.execute().print();
        
        
    }
}
